import baseUrl from './domain'
// // #ifdef MP-WEIXIN
// baseUrl = baseUrl + '/api'
// // #endif
console.log(baseUrl, 'baseUrl')
export const $request = (
	url,
	data = {},
	method = 'GET',
	isDomain = true,
	header = {
		'content-type': 'application/json'
	}
) => {
	// if (isDomain) {
	// 	const token = uni.getStorageSync('token')
		header['token'] = 'H5'
	// header['Authorization'] = 'H5'
	// }
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${baseUrl}/${url}`,
			data,
			method,
			header,
			success: res => {
				if (res.data.code == 200) {
					resolve(res.data)
				} else {
					wx.showToast({
						title: res.data.errMsg,
						icon: 'none'
					})
					reject(res.data)
				}
			},
			fail: error => {
				reject(error)
			}
		})
	})
}

export const $get = (url, data, isDomain) => {
	return $request(url, data, 'GET', isDomain)
}

export const $post = (url, data, isDomain) => {
	return $request(url, data, 'POST', isDomain)
}